#! /usr/bin/python
""" A python primer. pydoc, doctest and classes. 

Syntax:
 To generate man pages:
 > pydoc classtemplate

 To try all the tests in doctest.
 > python classtemplate.py -v
"""

#Class definition
class Tablerow:
	"""is the root-class for mapping rows from the database into the program.
	
	Doctest: here we insert python command lines inputs and outputs.
	>>> print Tablerow.database
	http://access.com/db
	"""

	#Data attributes here
	database='http://access.com/db'

	#Method attributes here
	def __init__(self,id,text):
		"""Initializes the id and textlabel data attributes.
		
		Doctest: Testing more data attributes defined at construction time
		>>> x = Tablerow(1,'coucou')
		>>> print x.id
		1
		>>> print x.textlabel
		coucou
		"""
		self.id=id
		self.textlabel=text

	#Constructor of a new tablerow by mapping it from a database!
	def openid(self,id):
		"""Creates a new Tablerow instance by reading input from a database.
	
		Must access database. Work in progress ...
		>>> y = Tablerow(1,'coucou')
		>>> print y.id
		1
		>>> print y.textlabel
		coucou
		>>> x = y.openid(5)
		>>> print x.id
		5
		>>> print x.database
		http://access.com/db
		"""
		#must access database and map entry to textlabel
		return Tablerow(id,'coucou')

	#Searches the database for a string
	def search(self,string):
		"""Searches for a tablerow containing the input string.

		Input: string to search for.
		Output: list of ids that match the string.

		Must access database. Work In Progress ...
		>>> n = Tablerow.search('coucou')
		>>> for i in n
		... print i
		...
		3
		"""
		return 3 

class Bot(Tablerow):
	"""Creates a new bot. 
	
	Whether it opens one defined in the database; whether it creates a new one.

	Tests that I want to perform with ...
	>>> x = Bot.openid(3)
	>>> print x.id
	3

	>>> n = Bot.search('coucou')
	>>> for i in n:
	... print i
	...
	3
	"""

def openid(id):
	"""Creates a new Tablerow instance by reading input from a database.

	>>> x = openid(5)
	>>> print x.id
	5
	"""
	#Must access database and map entry to textlabel
	return Tablerow(id,'coucou')

#docte -- "Debugging sucks :( Testing rocks :)"
def _test():
	"""Inline Doctest activated. Cool! :D
	This means that whenever the module is called in python
	
	> python thismodule.py -v
	
	the doctest function will try all the tests implemented in doctest.
	"""
	import doctest
	doctest.testmod()

if __name__ == "__main__":
	_test()
